int mostFrequent(int *nums, int numsSize, int key)
{
    int count = 0;
    int target = 0;
    for (int i = 1; i < numsSize; i++)
    {
        int res = 0;
        for (int j = 1; j < numsSize; j++)
        {
            if (nums[j - 1] == key && nums[j] == nums[i])
            {
                res++;
            }
        }
        if (res > count)
        {
            count = res;
            target = nums[i];
        }
    }
    return target;
}
